<template>
  <div>
    <h1>欢迎登录</h1>
    <van-cell-group>
      <van-field
        v-model="mobile"
        required
        label="文本"
        placeholder="请输入手机号"
      />
    </van-cell-group>
    <van-cell-group>
      <van-field
        v-model="password"
        required
        label="文本"
        placeholder="请输入密码"
      />
    </van-cell-group>
    <van-button type="primary" @click="login">登录</van-button>
  </div>
</template>

<script>
export default {
  data() {
    return {
      mobile: "",
      password: "",
    };
  },
  methods: {
    login() {
      this.axios
        .post("/login", { mobile: this.mobile, password: this.password })
        .then((res) => {
          console.log(res);
          if (res.data.code == 200) {
            localStorage.setItem("token", res.data.token);
            localStorage.setItem("userid", res.data.userid);
            alert(res.data.msg);
          }
        });
    },
  },
};
</script>

<style>
</style>